<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录测试</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        button {
            background: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background: #0056b3;
        }
        .result {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
        }
        .success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <h1>登录功能测试</h1>
    
    <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username" placeholder="请输入用户名">
    </div>
    
    <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" name="password" placeholder="请输入密码">
    </div>
    
    <button onclick="testLogin()">测试登录</button>
    <button onclick="testDashboard()">测试Dashboard页面</button>
    
    <div id="result"></div>
    
    <script>
        function testLogin() {
            var username = $('#username').val();
            var password = $('#password').val();
            
            if (!username || !password) {
                showResult('请输入用户名和密码', 'error');
                return;
            }
            
            var formData = {
                username: username,
                password: password
            };
            
            console.log('发送登录请求:', formData);
            
            $.post('/user/login', formData)
                .done(function(res) {
                    console.log('登录响应:', res);
                    if (res.code === 200) {
                        showResult('登录成功！响应: ' + JSON.stringify(res), 'success');
                        // 测试跳转
                        setTimeout(function() {
                            window.location.href = 'dashboard.html';
                        }, 2000);
                    } else {
                        showResult('登录失败: ' + (res.message || '未知错误'), 'error');
                    }
                })
                .fail(function(xhr, status, error) {
                    console.error('请求失败:', xhr, status, error);
                    showResult('网络错误: ' + error, 'error');
                });
        }
        
        function testDashboard() {
            window.location.href = 'dashboard.html';
        }
        
        function showResult(message, type) {
            $('#result').removeClass('success error').addClass(type).text(message);
        }
    </script>
</body>
</html> 